<script>
	$(document).ready(function () {
		//前端校验
		var formId = "${formId!}"; 	
		var divId = "${divId!}"; 
		var modalId = "${modalId!}"; 
		var method = "${method!}"; 
		if(divId!=''&&divId){
			$("#"+formId).validate({
				
				 submitHandler: function(form) {      
					 if(method=="post"){
						 postForm(formId);	
					}else{
						 if(modalId!=''&&modalId){
							 ajaxModalForm(modalId,divId, formId);
						 }else{
							 ajaxForm(divId, formId);
						 }
					}
				  },
			      errorPlacement: function(error, element) {
			    	  //错误信息的默认位置
// 			    	 var $id= element.attr("id");
// 			    	 var $errormsgspan = $("#" + $id + "-msgerror");
			    	 element.addClass("sign_input");
// 			    	 if ( $errormsgspan.length ){
// 				    	 error.appendTo($errormsgspan);
// 			    	 }else{
// 			    		 error.insertAfter(element)
// 			    	 }
				  },
				  success: function(label) {
					label.html("&nbsp;").addClass("checked");
				  }
				 })			
		}else{
			$("#"+formId).validate();
		}
		//后台校验结果处理
		setErrorMsg(${errorMsgJson!});
		//保持原先输入的值
		keepPara(${reqParaJson!});
	});
	
	function setErrorMsg(errorMsgJson){
		if(errorMsgJson){
	 		for(var error in errorMsgJson){
	 			var errorKey = error;
	 			var errorMsg = errorMsgJson[errorKey];
	 			var span=$("#"+errorKey+"-msgerror");
	 			var errorlabel="<label id=\""+errorKey+"-error\" class=\"error\" for=\""+errorKey+"\">"+errorMsg+"</label>";
	 			span.html(errorlabel);
			} 			
		}

	}
	function keepPara(reqParaJson){
		if(reqParaJson){
			console.log("reqPara string :"+JSON.stringify(reqParaJson));
	 		for(var reqPara in reqParaJson){
	 			var filedName = reqPara;
	 			var value = reqParaJson[reqPara];
	 			$("[name='"+filedName+"']").val(value);
			} 			
		}

	}	
</script>	
